﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace DinhTam
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                try
                {
                    if (Request.QueryString["act"].ToString()=="sanpham")
                    {
                        string tk = Request.QueryString["tk"].ToString();
                        if (tk != "")
                        {
                            txt_search.Text = tk;
                        }
                        if (Request.QueryString["ky"].ToString() != "")
                        {
                            for (int i = 0; i <= drop_tk.Items.Count - 1; i++)
                            {
                                if (Request.QueryString["ky"].ToString() == drop_tk.Items[i].Value.ToString())
                                {
                                    drop_tk.SelectedIndex = i;
                                }
                            }
                        }
                    }
                }
                catch { }

            HtmlMeta meta = new HtmlMeta();
            meta.Name = "Keywords";
            meta.Content = "Thời trang giá rẻ, Quần áo thời trang, Shop thời trang, Giarethoitrang.com";
            Page.Header.Controls.Add(meta);

            meta = new HtmlMeta();
            meta.Name = "Title";
            meta.Content = "Thời trang giá rẻ : Giarethoitrang.com";
            Page.Header.Controls.Add(meta);
            
            meta = new HtmlMeta();
            meta.Name = "Description";
            meta.Content = "Áo thun, Áo sơ mi, Áo kiểu, Váy, Đầm, Giá rẻ";
            Page.Header.Controls.Add(meta);
            
            Menu();
            Hot1();
            Hot2();
            Hot3();
            load_history();
          //  QC();

           
            }
            
        }
        //protected void QC()
        //{
        //    // QC Trai
        //     StringBuilder str = new StringBuilder();
        //     string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
        //     DataTable tb = new DataTable();
        //     tb = XLDL.XLDL.XLDaTa("select * from V_QC_Trai ORDER BY Ngay_Dang DESC");
        //     str.Append("<table width='100%'>");
        //    for(int i=0;i<tb.Rows.Count;i++)
        //    {
        //     str.Append("<tr>");
        //     str.Append("<td align='right'>");
        //     if (tb.Rows[i]["link"].ToString() == "")
        //     {
        //         str.Append("<img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' border='0' width='130px' alt='' />");
        //     }
        //     else
        //     {
        //         str.Append("<a href='" + tb.Rows[i]["link"].ToString() + "' target='_blank'><img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' border='0' width='130px' alt='' /></a>");
        //     } 
        //    str.Append("</td>");
        //    str.Append("</tr>");
        //    }
        //    str.Append("</table>");

        //    lbl_qc_trai.Text=str.ToString();

        //    // QC Phai
        //    str = new StringBuilder();
        //    tb = new DataTable();
        //    tb = XLDL.XLDL.XLDaTa("select * from V_QC_Phai ORDER BY Ngay_Dang DESC");
        //    str.Append("<table width='100%'>");
        //    for (int i = 0; i < tb.Rows.Count; i++)
        //    {
        //        str.Append("<tr>");
        //        str.Append("<td align='left'>");
        //        if (tb.Rows[i]["link"].ToString() == "")
        //        {
        //            str.Append("<img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' border='0' width='130px' alt='' />");
        //         }
        //        else
        //        {
        //            str.Append("<a href='" + tb.Rows[i]["link"].ToString() + "' target='_blank'><img src='" + path + tb.Rows[i]["hinh_anh"].ToString() + "' border='0' width='130px' alt='' /></a>");
        //        }
        //        str.Append("</td>");
        //        str.Append("</tr>");
        //    }
        //    str.Append("</table>");
        //    lbl_qc_phai.Text = str.ToString();
        //}
        protected void Hot1()
        {
            try
            {
                StringBuilder str = new StringBuilder();
                string img = "";
                string all = "";
                string h = "";
                string t = "";
                string w = "";
                string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
                DataTable tb = new DataTable();
                tb = XLDL.XLDL.XLDaTa("select * from V_SP_Hot ORDER BY Ngay_Dang_SP DESC");
                StreamReader f1 = new StreamReader(Server.MapPath("Js\\H.js"));
                StreamReader f2 = new StreamReader(Server.MapPath("Js\\W.js"));
                StreamReader f3 = new StreamReader(Server.MapPath("Js\\T.js"));

                h = f1.ReadToEnd();
                w = f2.ReadToEnd();
                t = f3.ReadToEnd();
                str.Append("<script type='text/javascript'>");
                str.Append("var firstreel=new reelslideshow({");
                str.Append("wrapperid: 'myreel2',");

                if (tb.Rows.Count != 0)
                {

                    for (int i = 0; i <= tb.Rows.Count - 1; i++)
                    {
                        if (i % 2 == 0)
                        {
                            img += "['" + path + tb.Rows[i]["Hinh_Anh"].ToString() + "','../index.aspx?act=chitiet&id=" + tb.Rows[i]["id_sp"].ToString() + "&nid=" + tb.Rows[i]["id_nhom_sp"].ToString() + "&Gt="+tb.Rows[i]["id_gt"].ToString()+"','_parent'],";
                            img += w;
                        }
                    }

                }
                else
                {
                    img += "['" + path + "071.jpg" + "','http://en.wikipedia.org/wiki/Cave','_parent'],";
                    img += w;
                }
                img = img.Replace("'", "\"");
                img = img.Trim();
                img = img.Remove(img.Length - 1, 1);
                all = str.ToString() + h + img + t + "<div id='myreel2'></div>";

                lbl_hot1.Text = all;
                f1.Close();
                f2.Close();
                f3.Close();
            }
            catch { }
    
        }
        protected void Hot2()
        {
            try
            {
                StringBuilder str = new StringBuilder();
                string img = "";
                string all = "";
                string h = "";
                string t = "";
                string w = "";
                string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
                DataTable tb = new DataTable();
                tb = XLDL.XLDL.XLDaTa("select * from V_SP_Hot ORDER BY Ngay_Dang_SP ASC");
                StreamReader f1 = new StreamReader(Server.MapPath("Js\\H.js"));
                StreamReader f2 = new StreamReader(Server.MapPath("Js\\W.js"));
                StreamReader f3 = new StreamReader(Server.MapPath("Js\\T.js"));

                h = f1.ReadToEnd();
                w = f2.ReadToEnd();
                t = f3.ReadToEnd();
                str.Append("<script type='text/javascript'>");
                str.Append("var firstreel=new reelslideshow({");
                str.Append("wrapperid: 'myreel3',");

                if (tb.Rows.Count != 0)
                {

                    for (int i = 0; i <= tb.Rows.Count - 1; i++)
                    {

                        img += "['" + path + tb.Rows[i]["Hinh_Anh"].ToString() + "','../index.aspx?act=chitiet&id=" + tb.Rows[i]["id_sp"].ToString() + "&nid=" + tb.Rows[i]["id_nhom_sp"].ToString() + "&Gt=" + tb.Rows[i]["id_gt"].ToString() + "','_parent'],";
                        img += w;

                    }

                }
                else
                {
                    img += "['" + path + "071.jpg" + "','http://en.wikipedia.org/wiki/Cave','_parent'],";
                    img += w;
                }
                img = img.Replace("'", "\"");
                img = img.Trim();
                img = img.Remove(img.Length - 1, 1);
                all = str.ToString() + h + img + t + "<div id='myreel3'></div>";

                lbl_hot2.Text = all;
                f1.Close();
                f2.Close();
                f3.Close();
            }
            catch { }
        }
        protected void Hot3()
        {
            try
            {
                StringBuilder str = new StringBuilder();
                string img = "";
                string all = "";
                string h = "";
                string t = "";
                string w = "";
                string path = System.Configuration.ConfigurationManager.AppSettings["Images_Path"];
                DataTable tb = new DataTable();
                tb = XLDL.XLDL.XLDaTa("select * from V_SP_Hot ORDER BY Ngay_Dang_SP DESC");
                StreamReader f1 = new StreamReader(Server.MapPath("Js\\H.js"));
                StreamReader f2 = new StreamReader(Server.MapPath("Js\\W.js"));
                StreamReader f3 = new StreamReader(Server.MapPath("Js\\T.js"));

                h = f1.ReadToEnd();
                w = f2.ReadToEnd();
                t = f3.ReadToEnd();
                str.Append("<script type='text/javascript'>");
                str.Append("var firstreel=new reelslideshow({");
                str.Append("wrapperid: 'myreel4',");
                if (tb.Rows.Count!= 0)
                {

                    for (int i = 0; i <= tb.Rows.Count - 1; i++)
                    {
                        if (i % 2 != 0)
                        {
                            img += "['" + path + tb.Rows[i]["Hinh_Anh"].ToString() + "','../index.aspx?act=chitiet&id=" + tb.Rows[i]["id_sp"].ToString() + "&nid=" + tb.Rows[i]["id_nhom_sp"].ToString() + "&Gt=" + tb.Rows[i]["id_gt"].ToString() + "','_parent'],";
                            img += w;
                        }
                    }

                }
                else
                {
                    img += "['" + path + "071.jpg" + "','http://en.wikipedia.org/wiki/Cave','_parent'],";
                    img += w;
                }
                img = img.Replace("'", "\"");
                img = img.Trim();
                img = img.Remove(img.Length - 1, 1);
                all = str.ToString() + h + img + t + "<div id='myreel4'></div>";

                lbl_hot3.Text = all;
                f1.Close();
                f2.Close();
                f3.Close();
            }
            catch { }

        }
        protected void Menu()
        {
            DataTable tb = new DataTable();
            string lenh = "select DISTINCT ten_nhom_sp, id_nhom_sp from V_NhomSP_Nu order by ten_nhom_sp asc";
            tb = XLDL.XLDL.XLDaTa(lenh);
            StringBuilder str = new StringBuilder();         

            str.Append("<div id='masterdiv'>");

            str.Append("<table border='0'>");
            str.Append("<tr>");
            str.Append("<td align='left'>");
            str.Append("<div class='menutitle' onclick='CloseAllSubMenu()'><a href='index.aspx?act=trangchu&nid=ud'><span style='color:#da0750; font-weight:bold; font-size: 13px'>MỚI CẬP NHẬT</span></a></div>");/*<img src='menu/star.gif' border='0' width='20px' />*/
            str.Append("</td>");
            str.Append("</tr>");
            str.Append("</table>");

            str.Append("<table border='0'>");
            str.Append("<tr>");
            str.Append("<td>");
            str.Append("<div class='menutitle' onclick=SwitchMenu('sub1')>THỜI TRANG NỮ</div>");/*<img src='menu/star.gif' border='0' width='20px' />*/
            str.Append("</td>");
            str.Append("</tr>");
            str.Append("</table>");
            str.Append("<span class='submenu' id='sub1'>");
            str.Append("<table border='0'>");
            for (int i = 0; i <= tb.Rows.Count - 1; i++)
            {

                str.Append("<tr>");
                str.Append("<td class='le'  align='left'>");
                str.Append("- <a href='index.aspx?act=sanpham&nid=" + tb.Rows[i]["ID_nhom_SP"].ToString() + "&Gt=1'>" + tb.Rows[i]["ten_nhom_SP"].ToString() + "</a><br>");
                str.Append("</td>");
                str.Append("</tr>");

            }
            str.Append("</table>");
            str.Append("</span>");

            tb.Clear();
            lenh = "select DISTINCT ten_nhom_sp, id_nhom_sp from V_NhomSP_Nam order by ten_nhom_sp asc";
            tb = XLDL.XLDL.XLDaTa(lenh);
            //  StringBuilder str = new StringBuilder();
            str.Append("<div id='masterdiv'>");
            str.Append("<table border='0'>");
            str.Append("<tr>");
            str.Append("<td>");
            str.Append("<div class='menutitle' onclick=SwitchMenu('sub2')>THỜI TRANG NAM</div>");/*<img src='menu/star.gif' border='0' width='20px' />*/
            str.Append("</td>");
            str.Append("</tr>");
            str.Append("</table>");
            str.Append("<span class='submenu' id='sub2'>");
            str.Append("<table border='0'>");
            for (int i = 0; i <= tb.Rows.Count - 1; i++)
            {

                str.Append("<tr>");
                str.Append("<td class='le'  align='left'>");
                str.Append("- <a href='index.aspx?act=sanpham&nid=" + tb.Rows[i]["ID_nhom_SP"].ToString() + "&Gt=2'>" + tb.Rows[i]["ten_nhom_SP"].ToString() + "</a><br>");
                str.Append("</td>");
                str.Append("</tr>");

            }
            str.Append("</table>");
            str.Append("</span>");

            tb.Clear();
            lenh = "select DISTINCT ten_nhom_sp, id_nhom_sp from V_NhomSP_Doi order by ten_nhom_sp asc";
            tb = XLDL.XLDL.XLDaTa(lenh);
            //  StringBuilder str = new StringBuilder();
            str.Append("<div id='masterdiv'>");
            str.Append("<table border='0'>");
            str.Append("<tr>");
            str.Append("<td>");
            str.Append("<div class='menutitle' onclick=SwitchMenu('sub3')>THỜI TRANG ĐÔI</div>");/*<img src='menu/star.gif' border='0' width='20px' />*/
            str.Append("</td>");
            str.Append("</tr>");
            str.Append("</table>");
            str.Append("<span class='submenu' id='sub3'>");
            str.Append("<table border='0'>");
            for (int i = 0; i <= tb.Rows.Count - 1; i++)
            {

                str.Append("<tr>");
                str.Append("<td class='le'  align='left'>");
                str.Append("- <a href='index.aspx?act=sanpham&nid=" + tb.Rows[i]["ID_nhom_SP"].ToString() + "&Gt=3'>" + tb.Rows[i]["ten_nhom_SP"].ToString() + "</a><br>");
                str.Append("</td>");
                str.Append("</tr>");

            }
            str.Append("</table>");
            str.Append("</span>");
            str.Append("</div>");



            this.Lbl_menu.Text = str.ToString();
        }

        protected void Img_search_Click(object sender, ImageClickEventArgs e)
        {
            
            Response.Redirect("index.aspx?act=sanpham&nid=tk&ky="+drop_tk.SelectedValue.ToString()+"&tk=" + this.txt_search.Text.Trim() + "");
            //if (Session["tk"].ToString() != "")
            //{
            //    txt_search.Text = Session["tk"].ToString();
            //}
            Session["tk"] = this.txt_search.Text.Trim();
            Session["ky"] = this.drop_tk.SelectedValue.ToString();
        }
        void load_history()
        {
            XLDL.XL_DS_DaXem his =(XLDL.XL_DS_DaXem) Session["his"];
            if (his.Rows.Count != 0)
            {
                lbl_history.Text = his.xuat();
                
           }
        }
        

        
    }
}
